Skip to content

Wrap alert text content in <p> to fix flex gap issue and improve semantics#42175

Merged
mdo merged 2 commits intov6-devfrom
v6-dev-fix-gap-issues-with-alerts
Mar 21, 2026
Merged

Wrap alert text content in <p> to fix flex gap issue and improve semantics#42175
mdo merged 2 commits intov6-devfrom
v6-dev-fix-gap-issues-with-alerts

Conversation

@julien-deramond
Copy link
Member

@julien-deramond julien-deramond commented Mar 13, 2026

Description

This PR fixes #42162.

There are several possible ways to address this issue; this PR proposes one approach.

As long as flex continues to be used in this way in v6, wrapping the text content resolves the issue observed in the documentation (and similar cases). In my opinion, this is not merely a workaround: our alerts could also benefit from the <p> semantics for accessibility. This approach is used in Boosted v5 (a customized fork of Bootstrap) and has been reviewed and approved by accessibility experts within the company, even though it differs slightly from the approach used in Bootstrap 5.

Checklist

  • js/tests/visual/alert.html

Rendering:

Screenshot 2026-03-13 at 21 23 18
  • js/tests/visual/dropdown-submenu.html

Rendering:

Screenshot 2026-03-13 at 21 23 47
  • scss/_alert.scss
  • site/src/assets/examples/cheatsheet/index.astro

Improved rendering in terms of gaps.

Screenshot 2026-03-13 at 21 27 22

⚠️ There's an issue with a part of the CSS not loaded here for the alert variants. Not coming from this PR. I've saved it in our document @mdo

  • site/src/assets/partials/snippets.js
  • site/src/content/docs/components/alert.mdx
  • site/src/content/docs/components/offcanvas.mdx
Screenshot 2026-03-13 at 21 31 59

⚠️ Same issue as for the Cheatsheet example page where the alert variant is not colored.

  • site/src/content/docs/customize/theme.mdx

Live previews

Related issues

Closes #42162

@include border-radius(var(--alert-border-radius));
}

.alert > p {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also use .mb-0 in code snippets.

Copy link

@pricop pricop Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 in favor of .mb-0 for the docs, if this is how it's used in other areas. It's very explicit and can be easly removed.

That way, if someone prefers something like margin: 1rem for all their p elements (this could be done to decorate paragraphs in a certain way), it won't be affected by the .alert > p rule, which in the case of this commit, only resets the bottom margin.

@julien-deramond julien-deramond requested a review from mdo March 13, 2026 20:33
@julien-deramond julien-deramond marked this pull request as ready for review March 13, 2026 20:33
@julien-deramond julien-deramond requested review from a team as code owners March 13, 2026 20:33
@julien-deramond julien-deramond force-pushed the v6-dev-fix-gap-issues-with-alerts branch from a12c031 to f634ca0 Compare March 13, 2026 20:38
@pricop
Copy link

pricop commented Mar 13, 2026

If there's an accessibility gain, then indeed we should use a <p> instead of <div> as the text wrapper, regardless of whether the gap utility gets removed or not.

Perhaps this is something should be considered though: #42175 (comment)

I personally can't say whether the gap should be removed or not. Seems useful, but also "hidden". It's easy enough to reset/customize with gap utilities, however.

A problem that I see if the gap doesn't get removed is that those who will migrate from v4 and v5, without this information being mentioned somewhere (Migration perhaps?), will be affected by this issue.

@mdo mdo force-pushed the v6-dev-fix-gap-issues-with-alerts branch from f634ca0 to 92a5b33 Compare March 21, 2026 16:06
@mdo mdo merged commit d1d5606 into v6-dev Mar 21, 2026
12 checks passed
@mdo mdo deleted the v6-dev-fix-gap-issues-with-alerts branch March 21, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

3 participants